// These 2 expansions are needed to make sure that everything is concatenated correctly.
#define Concat_Expansion2(x, y)	x##y
#define Concat_Expansion1(x, y) Concat_Expansion2(x, y)
#define Concat(x, y)			Concat_Expansion1(x, y)

// Sets up the CreateControl function and the factory switch.
#define StartControlTypes(_Next)										\
	Concat(																\
		{																\
			switch(_ControlType)										\
			{															\
			default:													\
				Error("Invalid control type specified.\n");				\
				return NULL;											\
			case Control::Type::Control:								\
				Error("Ordinary Controls cannot be instantiated.\n");	\
				return NULL;											\
	, _Next)												

// Creates a case statement for the type, sets up it's creation function and creates a list for it.
//#define AddControlType(_Type, _Next)									\
//	Concat(																\
//		case Control::Type::##_Type:									\
//			return ControlFactory::_Create##_Type();					\
//	, _Next)															\
//	_AddControlCreateFunc(_Type, ;)


// Creates a case statement for the type, creates a factory function and inserts _Func into that.
#define AddControlType(_Type, _Func, _Next)								\
	Concat(																\
		case Control::Type::##_Type:									\
			return ControlFactory::_Create##_Type();					\
	, _Next)															\
	_AddControlCreateFunc(_Type, _Func)

// Closes the factory switch.
#define EndControlTypes()												\
		};																\
	}

// Creates a factory function for the type and inserts _Func
#define _AddControlCreateFunc(_Type, _Func)								\
private:																\
	static Control* _Create##_Type()									\
	{																	\
		Controls::##_Type* obj = new Controls::##_Type();				\
		ControlMgr::AddControl(obj);									\
		_Func															\
		return obj;														\
	}